﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace l1cs.server.model.skill
{
    class L1SkillTimerTimerImpl : L1SkillTimer
    {
        private static Logger _log = Logger.getLogger( typeof( L1SkillTimerTimerImpl ).FullName );

        private Timer _future = null;

        public L1SkillTimerTimerImpl( L1Character cha, int skillId, int timeMillis )
        {
            _cha = cha;
            _skillId = skillId;
            _timeMillis = timeMillis;

            _remainingTime = _timeMillis / 1000;
        }

        public void SkillTimerSub( object state )
        {
            _remainingTime--;
            if ( _remainingTime <= 0 )
            {
                _cha.removeSkillEffect( _skillId );
            }
        }

        public void begin()
        {
            //    _future = GeneralThreadPool.getInstance().scheduleAtFixedRate(this, 1000, 1000);
            _future = new Timer( new TimerCallback( SkillTimerSub ), null, 1000, 1000 );
        }

        public void end()
        {
            kill();
            L1SkillStop.stopSkill( _cha, _skillId );
        }

        public void kill()
        {
            if ( _future != null )
            {
                _future.Dispose();
            }
        }

        public int getRemainingTime()
        {
            return _remainingTime;
        }

        private L1Character _cha;
        private int _timeMillis;
        private int _skillId;
        private int _remainingTime;
    }
}
